/*
 * Copyright (c) 2010-2011 GOV.
 * [Id:UserBean.java  11-8-20 下午4:57 poplar.mumu ]
 */
package org.mumu.pawn.beans.bam;

import com.google.common.collect.Lists;
import org.jboss.logging.Logger;
import org.mumu.pawn.cmps.UserCmp;
import org.mumu.pawn.domain.User;
import org.mumu.pawn.fm.BaseBean;
import org.mumu.pawn.fm.dm.LazyPawnDataModel;
import org.mumu.pawn.fm.util.QueryField;

import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;

/**
 * 用户管理的ManagerBean.
 * <br/>
 *
 * @author poplar.mumu
 * @version 1.0 2011-8-20 下午4:57
 * @since JDK 1.5
 */
@Named
@ViewScoped
public class UserBean extends BaseBean<User> {
    private static final long serialVersionUID = -3640971675617044424L;


    public void disabledUser() {
        logger.info("禁用用户：" + this.getEntity().getUserName());
        userCmp.disabledUser(this.getEntity());
    }

    @Override
    protected List<QueryField> initQueryFields() {
        //自定义查询
        List<QueryField> queryFields = Lists.newArrayList();
        queryFields.add(new QueryField("state", "2", QueryField.QUERYTYPE.NOT));
        return queryFields;
    }

    @Override
    protected LazyPawnDataModel<User> builderDataModel() {
        return userCmp.createUserDataModal();
    }

    @Override
    protected void doRemove() {
        userCmp.delteUser(this.getEntity());
    }

    @Override
    protected void doSave() {
        logger.info("编辑用户:" + this.getEntity().getUserName());
        userCmp.saveOrUpdateUser(this.getEntity());
    }


    /**
     * 注入用户服务
     */
    @Inject
    private UserCmp userCmp;

    @Inject
    private Logger logger;
}
